//
//  QMainChargeBookView.m
//  QoilPublic
//
//  Created by 杨凯 on 16/9/6.
//  Copyright © 2016年 杨凯. All rights reserved.
//

#import "QMainChargeBookView.h"
#import "QChargeBookModel.h"

@interface QMainChargeBookView()

@property (weak, nonatomic) IBOutlet UILabel *moneyLabel;

@property (weak, nonatomic) IBOutlet UILabel *allZLabel;

@property (weak, nonatomic) IBOutlet UILabel *allSLabel;
@end

@implementation QMainChargeBookView

- (void)awakeFromNib{
    [super awakeFromNib];
}

- (void)setHaveData:(BOOL)haveData{
    _haveData = haveData;
    if(!_haveData){
        _allZLabel.text = @"0.00";
        _allSLabel.text = @"0.00";
        _moneyLabel.text = @"0.00";
    }
}

- (void)setData:(NSArray *)data{

    _data = data;
    double allz = 0.00;//支出
    double alls = 0.00;//收入
    double allsum = 0.00;//相差
    
    for(int i=0; i<_data.count; ++i){
        QChargeBookModel *m = _data[i];
        if([m.accountTypeBean.accountTypeId isEqualToString:@"0"]){//支出
            NSString *moneS = m.accountTypeBean.money;
            double z = moneS.doubleValue;
            allz+=z;
        }else if ([m.accountTypeBean.accountTypeId isEqualToString:@"1"]){//收入
            NSString *moneS = m.accountTypeBean.money;
            double s = moneS.doubleValue;
            alls+=s;
        }
    }
    _allZLabel.text = [NSString stringWithFormat:@"￥%.2f",allz];
    _allSLabel.text = [NSString stringWithFormat:@"￥%.2f",alls];
    allsum = alls-allz;//收入减去支出的
   _moneyLabel.text = [NSString stringWithFormat:@"￥%.2f",allsum];
}
@end
